﻿using AutoMapper;
using BasicInformation.API.Application.Command.OutsourcingCommand;
using BasicInformation.Domain;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.OutsourcingCommandHandler
{
    public class OutsourcingUpdateCommandHandler : IRequestHandler<OutsourcingUpdateCommand, int>
    {
        private readonly IMapper mapper;
        private readonly IOutsourcingRepository outsourcingRepository;

        public OutsourcingUpdateCommandHandler(IMapper mapper, IOutsourcingRepository outsourcingRepository)
        {
            this.mapper = mapper;
            this.outsourcingRepository = outsourcingRepository;
        }
        public async Task<int> Handle(OutsourcingUpdateCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Outsourcing>(request);
            return await outsourcingRepository.Update(info);
        }
    }
}
